<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  
  <link rel="shortcut icon" href="../../img/favicon.ico">
  <title>融合层 Merge - Keras 中文文档</title>
  <link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>

  <link rel="stylesheet" href="../../css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../css/theme_extra.css" type="text/css" />
  <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css">
  
  <script>
    // Current page data
    var mkdocs_page_name = "\u878d\u5408\u5c42 Merge";
    var mkdocs_page_input_path = "layers/merge.md";
    var mkdocs_page_url = "/zh/layers/merge/";
  </script>
  
  <script src="../../js/jquery-2.1.1.min.js" defer></script>
  <script src="../../js/modernizr-2.8.3.min.js" defer></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script> 
  
  <script>
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

      ga('create', 'UA-61785484-1', 'keras.io');
      ga('send', 'pageview');
  </script>
  
</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
      <div class="wy-side-nav-search">
        <a href="../.." class="icon icon-home"> Keras 中文文档</a>
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" title="Type search term here" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
	<ul class="current">
	  
          
            <li class="toctree-l1">
		
    <a class="" href="../..">主页</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../../why-use-keras/">为什么选择 Keras?</a>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">快速开始</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../../getting-started/sequential-model-guide/">Sequential 顺序模型指引</a>
                </li>
                <li class="">
                    
    <a class="" href="../../getting-started/functional-api-guide/">函数式 API 指引</a>
                </li>
                <li class="">
                    
    <a class="" href="../../getting-started/faq/">FAQ 常见问题解答</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">模型</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../../models/about-keras-models/">关于 Keras 模型</a>
                </li>
                <li class="">
                    
    <a class="" href="../../models/sequential/">Sequential 顺序模型 API</a>
                </li>
                <li class="">
                    
    <a class="" href="../../models/model/">函数式 API</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">Layers</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../about-keras-layers/">关于 Keras 网络层</a>
                </li>
                <li class="">
                    
    <a class="" href="../core/">核心网络层</a>
                </li>
                <li class="">
                    
    <a class="" href="../convolutional/">卷积层 Convolutional</a>
                </li>
                <li class="">
                    
    <a class="" href="../pooling/">池化层 Pooling</a>
                </li>
                <li class="">
                    
    <a class="" href="../local/">局部连接层 Locally-connected</a>
                </li>
                <li class="">
                    
    <a class="" href="../recurrent/">循环层 Recurrent</a>
                </li>
                <li class="">
                    
    <a class="" href="../embeddings/">嵌入层 Embedding</a>
                </li>
                <li class=" current">
                    
    <a class="current" href="./">融合层 Merge</a>
    <ul class="subnav">
            
    <li class="toctree-l3"><a href="#add">Add</a></li>
    

    <li class="toctree-l3"><a href="#subtract">Subtract</a></li>
    

    <li class="toctree-l3"><a href="#multiply">Multiply</a></li>
    

    <li class="toctree-l3"><a href="#average">Average</a></li>
    

    <li class="toctree-l3"><a href="#maximum">Maximum</a></li>
    

    <li class="toctree-l3"><a href="#concatenate">Concatenate</a></li>
    

    <li class="toctree-l3"><a href="#dot">Dot</a></li>
    

    <li class="toctree-l3"><a href="#add_1">add</a></li>
    

    <li class="toctree-l3"><a href="#subtract_1">subtract</a></li>
    

    <li class="toctree-l3"><a href="#multiply_1">multiply</a></li>
    

    <li class="toctree-l3"><a href="#average_1">average</a></li>
    

    <li class="toctree-l3"><a href="#maximum_1">maximum</a></li>
    

    <li class="toctree-l3"><a href="#concatenate_1">concatenate</a></li>
    

    <li class="toctree-l3"><a href="#dot_1">dot</a></li>
    

    </ul>
                </li>
                <li class="">
                    
    <a class="" href="../advanced-activations/">高级激活层 Advanced Activations</a>
                </li>
                <li class="">
                    
    <a class="" href="../normalization/">标准化层 Normalization</a>
                </li>
                <li class="">
                    
    <a class="" href="../noise/">噪声层 Noise</a>
                </li>
                <li class="">
                    
    <a class="" href="../wrappers/">层封装器 wrappers</a>
                </li>
                <li class="">
                    
    <a class="" href="../writing-your-own-keras-layers/">编写你自己的层</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">数据预处理</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../../preprocessing/sequence/">序列预处理</a>
                </li>
                <li class="">
                    
    <a class="" href="../../preprocessing/text/">文本预处理</a>
                </li>
                <li class="">
                    
    <a class="" href="../../preprocessing/image/">图像预处理</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../../losses/">损失函数 Losses</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../../metrics/">评估标准 Metrics</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../../optimizers/">优化器 Optimizers</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../../activations/">激活函数 Activations</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../../callbacks/">回调函数 Callbacks</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../../datasets/">常用数据集 Datasets</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../../applications/">应用 Applications</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../../backend/">后端 Backend</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../../initializers/">初始化 Initializers</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../../regularizers/">正则化 Regularizers</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../../constraints/">约束 Constraints</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../../visualization/">可视化 Visualization</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../../scikit-learn-api/">Scikit-learn API</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../../utils/">工具</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../../contributing/">贡献</a>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">经典样例</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../../examples/addition_rnn/">Addition RNN</a>
                </li>
                <li class="">
                    
    <a class="" href="../../examples/babi_rnn/">Baby RNN</a>
                </li>
                <li class="">
                    
    <a class="" href="../../examples/babi_memnn/">Baby MemNN</a>
                </li>
                <li class="">
                    
    <a class="" href="../../examples/cifar10_cnn/">CIFAR-10 CNN</a>
                </li>
                <li class="">
                    
    <a class="" href="../../examples/cifar10_cnn_capsule/">CIFAR-10 CNN-Capsule</a>
                </li>
                <li class="">
                    
    <a class="" href="../../examples/cifar10_cnn_tfaugment2d/">CIFAR-10 CNN with augmentation (TF)</a>
                </li>
                <li class="">
                    
    <a class="" href="../../examples/cifar10_resnet/">CIFAR-10 ResNet</a>
                </li>
                <li class="">
                    
    <a class="" href="../../examples/conv_filter_visualization/">Convolution filter visualization</a>
                </li>
                <li class="">
                    
    <a class="" href="../../examples/image_ocr/">Image OCR</a>
                </li>
                <li class="">
                    
    <a class="" href="../../examples/imdb_bidirectional_lstm/">Bidirectional LSTM</a>
                </li>
    </ul>
	    </li>
          
        </ul>
      </div>
      &nbsp;
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="../..">Keras 中文文档</a>
      </nav>

      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="../..">Docs</a> &raquo;</li>
    
      
        
          <li>Layers &raquo;</li>
        
      
    
    <li>融合层 Merge</li>
    <li class="wy-breadcrumbs-aside">
      
        <a href="https://github.com/keras-team/keras-docs-zh/edit/master/docs/layers/merge.md"
          class="icon icon-github"> Edit on GitHub</a>
      
    </li>
  </ul>
  <hr/>
</div>
          <div role="main">
            <div class="section">
              
                <p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/layers/merge.py#L200">[source]</a></span></p>
<h3 id="add">Add</h3>
<pre><code class="python">keras.layers.Add()
</code></pre>

<p>计算输入张量列表的和。</p>
<p>它接受一个张量的列表，
所有的张量必须有相同的输入尺寸，
然后返回一个张量（和输入张量尺寸相同）。</p>
<p><strong>例子</strong></p>
<pre><code class="python">import keras

input1 = keras.layers.Input(shape=(16,))
x1 = keras.layers.Dense(8, activation='relu')(input1)
input2 = keras.layers.Input(shape=(32,))
x2 = keras.layers.Dense(8, activation='relu')(input2)
# 相当于 added = keras.layers.add([x1, x2])
added = keras.layers.Add()([x1, x2])  

out = keras.layers.Dense(4)(added)
model = keras.models.Model(inputs=[input1, input2], outputs=out)
</code></pre>

<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/layers/merge.py#L231">[source]</a></span></p>
<h3 id="subtract">Subtract</h3>
<pre><code class="python">keras.layers.Subtract()
</code></pre>

<p>计算两个输入张量的差。</p>
<p>它接受一个长度为 2 的张量列表，
两个张量必须有相同的尺寸，然后返回一个值为 (inputs[0] - inputs[1]) 的张量，
输出张量和输入张量尺寸相同。</p>
<p><strong>例子</strong></p>
<pre><code class="python">import keras

input1 = keras.layers.Input(shape=(16,))
x1 = keras.layers.Dense(8, activation='relu')(input1)
input2 = keras.layers.Input(shape=(32,))
x2 = keras.layers.Dense(8, activation='relu')(input2)
# 相当于 subtracted = keras.layers.subtract([x1, x2])
subtracted = keras.layers.Subtract()([x1, x2])

out = keras.layers.Dense(4)(subtracted)
model = keras.models.Model(inputs=[input1, input2], outputs=out)
</code></pre>

<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/layers/merge.py#L268">[source]</a></span></p>
<h3 id="multiply">Multiply</h3>
<pre><code class="python">keras.layers.Multiply()
</code></pre>

<p>计算输入张量列表的（逐元素间的）乘积。</p>
<p>它接受一个张量的列表，
所有的张量必须有相同的输入尺寸，
然后返回一个张量（和输入张量尺寸相同）。</p>
<hr />
<p><span style="float:right;">[[source]]<span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/layers/merge.py#L283">[source]</a></span></p>
<h3 id="average">Average</h3>
<pre><code class="python">keras.layers.Average()
</code></pre>

<p>计算输入张量列表的平均值。</p>
<p>它接受一个张量的列表，
所有的张量必须有相同的输入尺寸，
然后返回一个张量（和输入张量尺寸相同）。</p>
<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/layers/merge.py#L298">[source]</a></span></p>
<h3 id="maximum">Maximum</h3>
<pre><code class="python">keras.layers.Maximum()
</code></pre>

<p>计算输入张量列表的（逐元素间的）最大值。</p>
<p>它接受一个张量的列表，
所有的张量必须有相同的输入尺寸，
然后返回一个张量（和输入张量尺寸相同）。</p>
<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/layers/merge.py#L320">[source]</a></span></p>
<h3 id="concatenate">Concatenate</h3>
<pre><code class="python">keras.layers.Concatenate(axis=-1)
</code></pre>

<p>连接一个输入张量的列表。</p>
<p>它接受一个张量的列表，
除了连接轴之外，其他的尺寸都必须相同，
然后返回一个由所有输入张量连接起来的输出张量。</p>
<p><strong>参数</strong></p>
<ul>
<li><strong>axis</strong>: 连接的轴。</li>
<li><strong>**kwargs</strong>: 层关键字参数。</li>
</ul>
<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/layers/merge.py#L416">[source]</a></span></p>
<h3 id="dot">Dot</h3>
<pre><code class="python">keras.layers.Dot(axes, normalize=False)
</code></pre>

<p>计算两个张量之间样本的点积。</p>
<p>例如，如果作用于输入尺寸为 <code>(batch_size, n)</code> 的两个张量 <code>a</code> 和 <code>b</code>，
那么输出结果就会是尺寸为 <code>(batch_size, 1)</code> 的一个张量。
在这个张量中，每一个条目 <code>i</code> 是 <code>a[i]</code> 和 <code>b[i]</code> 之间的点积。</p>
<p><strong>参数</strong></p>
<ul>
<li><strong>axes</strong>: 整数或者整数元组，
一个或者几个进行点积的轴。</li>
<li><strong>normalize</strong>: 是否在点积之前对即将进行点积的轴进行 L2 标准化。
如果设置成 <code>True</code>，那么输出两个样本之间的余弦相似值。</li>
<li><strong>**kwargs</strong>: 层关键字参数。</li>
</ul>
<hr />
<h3 id="add_1">add</h3>
<pre><code class="python">keras.layers.add(inputs)
</code></pre>

<p><code>Add</code> 层的函数式接口。</p>
<p><strong>参数</strong></p>
<ul>
<li><strong>inputs</strong>: 一个输入张量的列表（列表大小至少为 2）。</li>
<li><strong>**kwargs</strong>: 层关键字参数。</li>
</ul>
<p><strong>返回</strong></p>
<p>一个张量，所有输入张量的和。</p>
<p><strong>例子</strong></p>
<pre><code class="python">import keras

input1 = keras.layers.Input(shape=(16,))
x1 = keras.layers.Dense(8, activation='relu')(input1)
input2 = keras.layers.Input(shape=(32,))
x2 = keras.layers.Dense(8, activation='relu')(input2)
added = keras.layers.add([x1, x2])

out = keras.layers.Dense(4)(added)
model = keras.models.Model(inputs=[input1, input2], outputs=out)
</code></pre>

<hr />
<h3 id="subtract_1">subtract</h3>
<pre><code class="python">keras.layers.subtract(inputs)
</code></pre>

<p><code>Subtract</code> 层的函数式接口。</p>
<p><strong>参数</strong></p>
<ul>
<li><strong>inputs</strong>: 一个列表的输入张量（列表大小准确为 2）。</li>
<li><strong>**kwargs</strong>: 层的关键字参数。</li>
</ul>
<p><strong>返回</strong></p>
<p>一个张量，两个输入张量的差。</p>
<p><strong>例子</strong></p>
<pre><code class="python">import keras

input1 = keras.layers.Input(shape=(16,))
x1 = keras.layers.Dense(8, activation='relu')(input1)
input2 = keras.layers.Input(shape=(32,))
x2 = keras.layers.Dense(8, activation='relu')(input2)
subtracted = keras.layers.subtract([x1, x2])

out = keras.layers.Dense(4)(subtracted)
model = keras.models.Model(inputs=[input1, input2], outputs=out)
</code></pre>

<hr />
<h3 id="multiply_1">multiply</h3>
<pre><code class="python">keras.layers.multiply(inputs)
</code></pre>

<p><code>Multiply</code> 层的函数式接口。</p>
<p><strong>参数</strong></p>
<ul>
<li><strong>inputs</strong>: 一个列表的输入张量（列表大小至少为 2）。</li>
<li><strong>**kwargs</strong>: 层的关键字参数。</li>
</ul>
<p><strong>返回</strong></p>
<p>一个张量，所有输入张量的逐元素乘积。</p>
<hr />
<h3 id="average_1">average</h3>
<pre><code class="python">keras.layers.average(inputs)
</code></pre>

<p><code>Average</code> 层的函数式接口。</p>
<p><strong>参数</strong></p>
<ul>
<li><strong>inputs</strong>: 一个列表的输入张量（列表大小至少为 2）。</li>
<li><strong>**kwargs</strong>: 层的关键字参数。</li>
</ul>
<p><strong>返回</strong></p>
<p>一个张量，所有输入张量的平均值。</p>
<hr />
<h3 id="maximum_1">maximum</h3>
<pre><code class="python">keras.layers.maximum(inputs)
</code></pre>

<p><code>Maximum</code> 层的函数式接口。</p>
<p><strong>参数</strong></p>
<ul>
<li><strong>inputs</strong>: 一个列表的输入张量（列表大小至少为 2）。</li>
<li><strong>**kwargs</strong>: 层的关键字参数。</li>
</ul>
<p><strong>返回</strong></p>
<p>一个张量，所有张量的逐元素的最大值。</p>
<hr />
<h3 id="concatenate_1">concatenate</h3>
<pre><code class="python">keras.layers.concatenate(inputs, axis=-1)
</code></pre>

<p><code>Concatenate</code> 层的函数式接口。</p>
<p><strong>参数</strong></p>
<ul>
<li><strong>inputs</strong>: 一个列表的输入张量（列表大小至少为 2）。</li>
<li><strong>axis</strong>: 串联的轴。</li>
<li><strong>**kwargs</strong>: 层的关键字参数。</li>
</ul>
<p><strong>返回</strong></p>
<p>一个张量，所有输入张量通过 <code>axis</code> 轴串联起来的输出张量。</p>
<hr />
<h3 id="dot_1">dot</h3>
<pre><code class="python">keras.layers.dot(inputs, axes, normalize=False)
</code></pre>

<p><code>Dot</code> 层的函数式接口。</p>
<p><strong>参数</strong></p>
<ul>
<li><strong>inputs</strong>: 一个列表的输入张量（列表大小至少为 2）。</li>
<li><strong>axes</strong>: 整数或者整数元组，
一个或者几个进行点积的轴。</li>
<li><strong>normalize</strong>: 是否在点积之前对即将进行点积的轴进行 L2 标准化。
如果设置成 True，那么输出两个样本之间的余弦相似值。</li>
<li><strong>**kwargs</strong>: 层的关键字参数。</li>
</ul>
<p><strong>返回</strong></p>
<p>一个张量，所有输入张量样本之间的点积。</p>
              
            </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="../advanced-activations/" class="btn btn-neutral float-right" title="高级激活层 Advanced Activations">Next <span class="icon icon-circle-arrow-right"></span></a>
      
      
        <a href="../embeddings/" class="btn btn-neutral" title="嵌入层 Embedding"><span class="icon icon-circle-arrow-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <!-- Copyright etc -->
    
  </div>

  Built with <a href="http://www.mkdocs.org">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
      
        </div>
      </div>

    </section>

  </div>

  <div class="rst-versions" role="note" style="cursor: pointer">
    <span class="rst-current-version" data-toggle="rst-current-version">
      
          <a href="https://github.com/keras-team/keras-docs-zh/" class="fa fa-github" style="float: left; color: #fcfcfc"> GitHub</a>
      
      
        <span><a href="../embeddings/" style="color: #fcfcfc;">&laquo; Previous</a></span>
      
      
        <span style="margin-left: 15px"><a href="../advanced-activations/" style="color: #fcfcfc">Next &raquo;</a></span>
      
    </span>
</div>
    <script>var base_url = '../..';</script>
    <script src="../../js/theme.js" defer></script>
      <script src="../../search/main.js" defer></script>

</body>
</html>
